package it.storm.solution;

import java.util.ArrayList;
import java.util.List;

/**
 * 1672. 最富有客户的资产总量
 * https://leetcode-cn.com/problems/richest-customer-wealth/
 */
public class Solutions_1672 {
    public static void main(String[] args) {
        int[][] accounts1 = {{1, 2, 3}, {3, 2, 1}};  // output: 6
        int[][] accounts2 = {{1, 5}, {7, 3}, {3, 5}};  // output: 10
        int[][] accounts3 = {{2, 8, 7}, {7, 1, 3}, {1, 9, 5}};  // output: 17

        List<int[][]> inputs = new ArrayList<>();
        inputs.add(accounts1);
        inputs.add(accounts2);
        inputs.add(accounts3);

        for (int[][] input : inputs) {
            int result = maximumWealth(input);
            System.out.println(result);
        }
    }

    /**
     * 计算得到二维数组 accounts 中，各一维数组的元素和的最大值
     */
    public static int maximumWealth(int[][] accounts) {
        int res = 0;
        for (int[] account : accounts) {
            int cur = 0;
            for (int i = 0; i < account.length; i++) {
                cur += account[i];
            }
            res = Math.max(res, cur);
        }
        return res;
    }
}
